package com.baizhi.action;

import com.baizhi.entity.Class;
import com.baizhi.entity.Group;
import com.baizhi.entity.Tag;
import com.baizhi.service.GroupService;
import com.baizhi.service.StudentService;
import com.baizhi.service.impl.GroupServiceImpl;
import com.baizhi.service.impl.StudentServiceImpl;
import com.baizhi.service.impl.TagServiceImpl;
import com.baizhi.service.tagService;
import com.opensymphony.xwork2.ActionSupport;

import java.sql.Date;
import java.util.List;

public class GroupAction extends ActionSupport {
    /* 标签对象 */
    Group group;
    int id;
    List<Group> groups;
    List<Class> classes;
    List<Tag> tags;


    /* 查询班级名字  用于添加小组时 遍历所有班级以供选择 */
    public String queryGroupClazz(){

        GroupService gs =new GroupServiceImpl();
        classes = gs.selectGroupClass();
        System.out.println(classes);

        return "queryGroupClazzsuccess";
    }


    /* 添加小组 */
   public String insertGroup(){

       GroupService gs = new GroupServiceImpl();
       group.setCreateDate(new java.util.Date());

       gs.insertGroup(group);

       return "insertsuccess";
   }




    /* //删除小组 */
    public String deleteGroup(){

        GroupService gs = new GroupServiceImpl();
        gs.deleteById(id);

       return "delectsuccess";
    }


    /*  //查询所有小组 */
    public String queryAllGroups(){

        GroupService gs = new GroupServiceImpl();
        groups = gs.queryAll();
        for (Group group : groups) {
            group.setCreateDate(new Date(group.getCreateDate().getTime()));
        }

        StudentService ss =new StudentServiceImpl();
        /* 拿到小组人数*/
        for (Group group2 : groups) {
            group2.setSize(ss.queryNumberByGroupId(group2.getId()));
            System.out.println(ss.queryNumberByGroupId(group2.getId()));
        }

        tagService ts = new TagServiceImpl();
        tags = ts.queryAllTagByType("学生");

        return "queryAllsuccess";
    }



    //get/set
    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List<Group> getGroups() {
        return groups;
    }

    public void setGroups(List<Group> groups) {
        this.groups = groups;
    }

    public List<Class> getClasses() {
        return classes;
    }

    public void setClasses(List<Class> classes) {
        this.classes = classes;
    }

    public List<Tag> getTags() {
        return tags;
    }

    public void setTags(List<Tag> tags) {
        this.tags = tags;
    }
}
